var Agent = {
    mysubmit: function(){
        var url = $('#baseurl').val()+"/customer/agent/optionapply";
        var applyStatus = $('#applystatus').val();
        var applyID = $('#applyid').val(); 
        if(applyStatus == "4"){
            var campusName = $("#campusesName").val();
            var campusID = $("#campusesID").val();
            var deputyID = "0";
            if(campusName == "" || campusID == "0"){
                $("#deputyErroMsg").html("<font color ='red'>请选择高校</font>");
                return;
            }
            var is_ambassador = '1';
            if($("#ambassador").attr("checked")){
                is_ambassador = "3";
            }
            if($("#deputy").attr("checked")){
                is_ambassador = "4";
                deputyID = $("#deputyID").val();
                if(deputyID == "0"){
                    $("#deputyErrorMsg").html("<font color ='red'>请选择上级代理</font>");
                    return;
                }
            }
             if($("#pratiseStart").attr("checked")){
                is_ambassador = "6";
            }
            $.post(url, {
                "applyStatus": applyStatus,
                "applyID":applyID,
                "campusID":campusID,
                "is_ambassador":is_ambassador,
                "deputyID":deputyID
            },
            function (data){
                window.location.href = $('#baseurl').val()+"/customer/agent/showapply";
            },'json');
        }else{
            $.post(url, {
                "applyStatus": applyStatus,
                "applyID":applyID
            },
            function (data){
                  window.location.href = $('#baseurl').val()+"/customer/agent/showapply";
            },'json');
        }
    },
    changeapplystatus : function (){
        var applyStatus = $('#applystatus').val();
        if(applyStatus == '4'){
            $('#promot').show();
            $('#username').show();
            $('#choosecampus').show();
            if($('#deputy').attr("checked")){
                Agent.showdeputy();
            };
            $('#certf').show();
        }else{
            $('#promot').hide();
            $('#username').hide();
            $('#choosecampus').hide();
            $('#certf').hide();
            $('#highdeputy').hide();
        }
    },
    showdeputy : function (){  
        var campusID = $("#campusesID").val();
        if(campusID == '0' || campusID == "" || campusID == null){
            $("#deputyErroMsg").html("<font color ='red'>请选择高校</font>");
            return;
        }
        $('#highdeputy').show();
        $("#deputyErrorMsg").html("");
    },
    hidedeputy : function (id){
        $("input[name='certf_level']").each(function (){
            if(id == $(this).attr('id')){
                $('#'+id).attr("checked","checked");
                if(id == 'deputy'){
                    Agent.showdeputy();
                }else{
                    $('#highdeputy').hide();
                }
            }else{
                $('#'+$(this).attr('id')).removeAttr("checked");
            }
        });
    },
    deleteApply : function (){
        var applyid = $("#applyid").val();
        var url = $('#baseurl').val()+"/customer/agent/deloneapply";
        window.location.href = url+"/id/"+applyid;
    }
}